package com.util;

import java.io.File;

import javax.imageio.stream.FileImageOutputStream;

public class Yutil {

	public String byteToString(byte[] data) {
		String dataString = null;
		try {
			// 将字节数组转为字符串，编码格式为UTF-8
			dataString = new String(data, "UTF-8");
		} catch (Exception e) {
			e.printStackTrace();

		}
		return dataString;
	}

	public static int byte2image(byte[] data, String path) {
		if (data.length < 3 || path.equals(""))
			return 0;
		try {
			FileImageOutputStream imageOutput = new FileImageOutputStream(new File(path));
			imageOutput.write(data, 0, data.length);
			imageOutput.close();
			System.out.println("Make Picture success,Please find image in " + path);
			return 1;
			
		} catch (Exception ex) {
			System.out.println("Exception: " + ex);
			ex.printStackTrace();
			return 0;
		}
	}
}
